﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using G.Navigate;

namespace G.Reader.View.Message
{
    public partial class MessagePage : GBasePage
    {
        //UserInfoService.UserInfoServiceClient client = new UserInfoService.UserInfoServiceClient();
        public MessagePage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            ViewModel.MessageViewModel.Instance.Initial();
            //if (listbox_friends.ItemsSource == null)
            //{
            //    client.GetFriendsByUserIdCompleted += new EventHandler<UserInfoService.GetFriendsByUserIdCompletedEventArgs>(client_GetFriendsByUserIdCompleted);
            //    client.GetFriendsByUserIdAsync(GloabalData.Instance.User.Id);
            //}
        }

        void client_GetFriendsByUserIdCompleted(object sender, UserInfoService.GetFriendsByUserIdCompletedEventArgs e)
        {
            this.listbox_friends.ItemsSource = e.Result;
        }

        private void btnAddUser_Click(object sender, EventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/View/Message/SearchFriendPage.xaml", UriKind.Relative));
        }

        private void listbox_friends_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listbox_friends.SelectedItem != null)
            {
                this.NavigationService.Navigate("/View/Message/ChatPage.xaml", listbox_friends.SelectedItem);
                listbox_friends.SelectedItem = null;
            }
        }
    }
}